package com.ice.project.datamining.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.ice.project.dataminig.listener.MainWindowListener;

public class FormPanel extends JPanel {
	private MainWindow parentWindow;
	private JPanel mainPanel;
	
	private JComboBox jcCheckingStatus;
	private JComboBox jcCreditHistory;
	private JComboBox jcPurpose;
	private JComboBox jcSavingStatus;
	private JComboBox jcEmployment;
	private JComboBox jcPropertyMagnitude;
	private JComboBox jcHousing;



	
	private JButton jbSubmit;
	
	public FormPanel(MainWindow mw) {
		super(new BorderLayout());
		parentWindow = mw;
		initializeGUI();
	}

	private void initializeGUI() {		
		mainPanel = new JPanel();
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
		
		JLabel title = new JLabel("<html><u>Client data</u></html>", SwingConstants.CENTER);
		title.setFont(new Font("Arial",Font.BOLD, 18));
		title.setAlignmentX(Component.CENTER_ALIGNMENT);
		mainPanel.add(title);
	
		mainPanel.add(getForm());
		
		jbSubmit = new JButton("Submit data");
		jbSubmit.setAlignmentX(Component.CENTER_ALIGNMENT);
		
		jbSubmit.setActionCommand("Submit");
		jbSubmit.addActionListener(new MainWindowListener(parentWindow));

		mainPanel.add(jbSubmit);
		
		this.add(mainPanel);
	}
	
	private JPanel getForm() {
		JPanel formPanel = new JPanel();
		formPanel = new JPanel(new GridBagLayout());
		
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.ipady=0;
		gbc.ipadx=0;
		gbc.fill = GridBagConstraints.BOTH;
		
		gbc.anchor = GridBagConstraints.WEST;
		
		gbc.gridx=0;
		gbc.gridy=0;		
		formPanel.add(new JLabel("Checking status"), gbc);		
		jcCheckingStatus = new JComboBox();
		jcCheckingStatus.addItem("<0");
		jcCheckingStatus.addItem("0<=X<200");
		jcCheckingStatus.addItem(">=200");
		jcCheckingStatus.addItem("no checking");	
		gbc.gridx=1;
		gbc.gridy=0;
		formPanel.add(jcCheckingStatus, gbc);
		
		gbc.gridx=2;
		gbc.gridy=0;
		formPanel.add(new JLabel("Credit history"), gbc);
		jcCreditHistory = new JComboBox();
		jcCreditHistory.addItem("no credits/all paid");
		jcCreditHistory.addItem("all paid");
		jcCreditHistory.addItem("existing paid");
		jcCreditHistory.addItem("delayed previously");
		jcCreditHistory.addItem("critical/other existing credit");			
		gbc.gridx=3;
		gbc.gridy=0;
		formPanel.add(jcCreditHistory,gbc);
		
		gbc.gridx=0;
		gbc.gridy=1;
		formPanel.add(new JLabel("Purpose"),gbc);
		jcPurpose = new JComboBox();
		jcPurpose.addItem("new car");
		jcPurpose.addItem("used car");
		jcPurpose.addItem("furniture/equipment");
		jcPurpose.addItem("radio/tv");
		jcPurpose.addItem("domestic appliance");
		jcPurpose.addItem("repairs");
		jcPurpose.addItem("education");
		jcPurpose.addItem("vacation");
		jcPurpose.addItem("retraining");
		jcPurpose.addItem("business");
		jcPurpose.addItem("other");		
		gbc.gridx=1;
		gbc.gridy=1;
		formPanel.add(jcPurpose, gbc);
		
		gbc.gridx=2;
		gbc.gridy=1;
		formPanel.add(new JLabel("Savings status"), gbc);
		jcSavingStatus = new JComboBox();
		jcSavingStatus.addItem("<100");
		jcSavingStatus.addItem("100<=X<500");
		jcSavingStatus.addItem("500<=X<1000");
		jcSavingStatus.addItem(">=1000");
		jcSavingStatus.addItem("no known savings");	
		gbc.gridx=3;
		gbc.gridy=1;
		formPanel.add(jcSavingStatus, gbc);
		
		gbc.gridx=0;
		gbc.gridy=2;
		formPanel.add(new JLabel("employment"), gbc);
		jcEmployment = new JComboBox();
		jcEmployment.addItem("unemployed");
		jcEmployment.addItem("<1");
		jcEmployment.addItem("1<=X<4");
		jcEmployment.addItem("4<=X<7");
		jcEmployment.addItem(">=7");
		gbc.gridx=1;
		gbc.gridy=2;
		formPanel.add(jcEmployment, gbc);
			
		gbc.gridx=2;
		gbc.gridy=2;
		formPanel.add(new JLabel("Property magnitude"), gbc);
		jcPropertyMagnitude = new JComboBox();
		jcPropertyMagnitude.addItem("real estate");
		jcPropertyMagnitude.addItem("life insurance");
		jcPropertyMagnitude.addItem("car");
		jcPropertyMagnitude.addItem("no known property");
		gbc.gridx=3;
		gbc.gridy=2;
		formPanel.add(jcPropertyMagnitude, gbc);
			
		
		gbc.gridx=0;
		gbc.gridy=3;
		formPanel.add(new JLabel("Housing"), gbc);
		jcHousing = new JComboBox();
		jcHousing.addItem("rent");
		jcHousing.addItem("own");
		jcHousing.addItem("for free");
		gbc.gridx=1;
		gbc.gridy=3;
		formPanel.add(jcHousing, gbc);
			

		

				
		this.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
	
		return formPanel;	
	}

	public MainWindow getParentWindow() {
		return parentWindow;
	}

	public JPanel getMainPanel() {
		return mainPanel;
	}

	public JComboBox getJcCheckingStatus() {
		return jcCheckingStatus;
	}

	public JComboBox getJcCreditHistory() {
		return jcCreditHistory;
	}

	public JComboBox getJcPurpose() {
		return jcPurpose;
	}

	public JComboBox getJcSavingStatus() {
		return jcSavingStatus;
	}

	public JComboBox getJcEmployment() {
		return jcEmployment;
	}

	public JComboBox getJcPropertyMagnitude() {
		return jcPropertyMagnitude;
	}

	public JButton getJbSubmit() {
		return jbSubmit;
	}

	public JComboBox getJcHousing() {
		return jcHousing;
	}
	
	
}
